/*
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License");  you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * http//www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 *
 * The Original Code is OntologyIndexer.
 *
 * The Initial Developer of the Original Code is University of Roma Tor Vergata.
 * Portions created by University of Roma Tor Vergata are Copyright (C) 2006.
 * All Rights Reserved.
 *
 * OntologyIndexer was developed by the Artificial Intelligence Research Group
 * (ai-nlp.info.uniroma2.it) at the University of Roma Tor Vergata
 * Current information about OntologyIndexer can be obtained at 
 * http//ai-nlp.info.uniroma2.it/software/...
 *
 */

package it.uniroma2.art.owlart.langsearch.utilities;

import it.uniroma2.art.owlart.exceptions.ModelAccessException;
import it.uniroma2.art.owlart.model.ARTURIResource;
import it.uniroma2.art.owlart.models.OWLModel;
import it.uniroma2.art.owlart.navigation.ARTNamespaceIterator;

import java.util.ArrayList;
import java.util.Collection;


/**
 * @author Armando Stellato <stellato@info.uniroma2.it>
 */
public class OntologyUtilities {
       
    
    /**
     * @param m the OntModel which is queried by this method
     * @param localName the local name used to retrieve the classes
     * @return the set of classes which have the same localname given by the <code>localName</code> parameter
     * @throws ModelAccessException 
     */
    public static Collection<ARTURIResource> getClassesByLocalName(OWLModel m, String localName) throws ModelAccessException {
    	ArrayList<ARTURIResource> result = new ArrayList<ARTURIResource>();           
        ARTNamespaceIterator nsIt = m.listNamespaces();
        ARTURIResource c;
        while (nsIt.streamOpen()) {            
            String URI = nsIt.getNext()+ localName;     
            System.out.println("trying URI: " + URI);
            c = m.retrieveClass(URI);
            if (c!=null) {            	
            	result.add(c);
            }
        }
        nsIt.close();
        return result;
    }
 
    /**
     * @param m the OntModel which is queried by this method
     * @param localName the local name used to retrieve the properties
     * @return the set of properties which have the same localname given by the <code>localName</code> parameter
     * @throws ModelAccessException 
     */    
    public static Collection<ARTURIResource> getPropertiesByLocalName(OWLModel m, String localName) throws ModelAccessException {
    	ArrayList<ARTURIResource> result = new ArrayList<ARTURIResource>();           
        ARTNamespaceIterator nsIt = m.listNamespaces();
        ARTURIResource c;
        while (nsIt.streamOpen()) {            
            String URI = nsIt.getNext()+ localName;     
            System.out.println("trying URI: " + URI);
            c = m.retrieveURIResource(URI);
            if (c!=null) {            	
            	result.add(c);
            }
        }
        nsIt.close();
        return result;
    }
    
    /**
     * @param m the OntModel which is queried by this method
     * @param localName the local name used to retrieve the individuals
     * @return the set of individuals which have the same localname given by the <code>localName</code> parameter
     * @throws ModelAccessException 
     */      
    public static Collection<ARTURIResource> getIndividualsByLocalName(OWLModel m, String localName) throws ModelAccessException {
    	ArrayList<ARTURIResource> result = new ArrayList<ARTURIResource>();           
        ARTNamespaceIterator nsIt = m.listNamespaces();
        ARTURIResource c;
        while (nsIt.streamOpen()) {            
            String URI = nsIt.getNext()+ localName;     
            System.out.println("trying URI: " + URI);
            c = m.retrieveURIResource(URI);
            if (c!=null) {            	
            	result.add(c);
            }
        }
        nsIt.close();
        return result;
    }
                
}